/***********************************
*
* author:huanglei
* mail:code.huanglei@gmail.com
* version:0.1
*
***********************************/

function $(value){
	if (value.indexOf('.') == 0){
		return document.getElementsByClassName(value.substring(1));
	} else if (value.indexOf('#') == 0){
		return parent.document.getElementById(value.substring(1));
	} else {
		return document.getElementsByTagName(value);
	}
}


document.getElementsByClassName = function(className,elm) {  
    var testClass = new RegExp("(^|\s)" + className + "(\s|$)");  
    elm = elm || document
    var elements = elm.all? elm.all : elm.getElementsByTagName("*");  
    var returnElements = [];  
    var current;  
    var length = elements.length;  
    for(var i=0; i<length; i++){  
        current = elements[i];  
        if(testClass.test(current.className)){  
            returnElements.push(current);  
        }  
    }  
    return returnElements;  
}  

Array.prototype.each=function(f){
	try{
		for(var i=0;i<this.length;i++){
			try{
				f(this[i],i,this)
			}catch(e){}
		}
	}catch(e){}
}

Array.prototype.set = function(value){
	for(var i=0;i<this.length;i++){
		if(this[i] == value) return false;
	}
	
	this.push(value);
}



